package Server.Jsmj.RGCP.QILE;

import java.util.ArrayList;
import java.util.List;

public class HuCard {
	
	public List<HuBlock> list;
	
	public HuCard(){
		list = new ArrayList<HuBlock>();
	}
	
	public void addHuBlock(HuBlock block){
		this.list.add(block);
	}
	
	public void removeHuBlock(HuBlock block){
		this.list.remove(block);
	}
	public void removeHuBlock(int index){
		this.list.remove(index);
	}
	public void removeHuBlock(){
		this.list.remove(list.size()-1);
	}
	
	@Override
	public String toString() {
		String s = "";
		if(this.list != null){
			for(HuBlock block : this.list){
				s += block.toString()+"  ";
			}
		}
		return s;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null){
			return false;
		}
		if(obj instanceof HuCard){
			HuCard objHuCard = (HuCard) obj;
			if(this.list == null && objHuCard.list == null){
				return true;
			}
			if(this.list.size() == 0 && objHuCard.list.size() == 0){
				return true;
			}
			if(this.list.size() != objHuCard.list.size()){
				return false;
			}
			try {
				HuCard _this = this.clone();
				objHuCard = objHuCard.clone();
				a:for(int i =0; i < _this.list.size(); i++){
					b:for(int j = 0; j < objHuCard.list.size(); j++){
						if(_this.list.get(i).equals(objHuCard.list.get(j))){
							_this.list.remove(i);
							objHuCard.list.remove(j);
							i--;
							j--;
							break b;
						}
					}
				}
				if(_this.list.size() == 0 && objHuCard.list.size() == 0){
					return true;
				}
			} catch (CloneNotSupportedException e) {
				e.printStackTrace();
				return false;
			}
		}
		return false;
	}
	
	@Override
	protected HuCard clone() throws CloneNotSupportedException {
		HuCard huCard = new HuCard();
		for(HuBlock huBlock : this.list){
			huCard.addHuBlock(huBlock.clone());
		}
		return huCard;
	}
	
}
